/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
#include <engine/e_server_interface.h>
#include <game/mapitems.hpp>
#include <game/server/entities/character.hpp>
#include <game/server/player.hpp>
#include <game/server/entities/pickup.hpp>
#include <engine/e_config.h>
#include "arena.hpp"

GAMECONTROLLER_WA::GAMECONTROLLER_WA()
{
	if(config.sv_gametype_mod)
	gametype = "mWA";
	else
	gametype = "WA";
}

void GAMECONTROLLER_WA::tick()
{
	do_player_score_wincheck();
	GAMECONTROLLER::tick();
}

bool GAMECONTROLLER_WA::on_entity(int index, vec2 pos)
{
	int type = -1;
	int subtype = 0;
	
	if(index == ENTITY_SPAWN)
		spawn_points[0][num_spawn_points[0]++] = pos;
	else if(index == ENTITY_SPAWN_RED)
		spawn_points[1][num_spawn_points[1]++] = pos;
	else if(index == ENTITY_SPAWN_BLUE)
		spawn_points[2][num_spawn_points[2]++] = pos;
	else if(index == ENTITY_ARMOR_1)
		type = POWERUP_ARMOR;
	else if(index == ENTITY_HEALTH_1)
		type = POWERUP_HEALTH;
	else if(index == ENTITY_WEAPON_SHOTGUN || index == ENTITY_WEAPON_GRENADE ||index == ENTITY_WEAPON_RIFLE)
			switch(config.sv_weapon_arena)
			{
				case 2:
				type = POWERUP_WEAPON;
				subtype = WEAPON_SHOTGUN;
				break;
				case 3:
				type = POWERUP_WEAPON;
				subtype = WEAPON_GRENADE;
				break;
				case 4:
				type = POWERUP_WEAPON;
				subtype = WEAPON_RIFLE;
				break;
				default:
				break;
			}
		{}
	if(type != -1)
	{
		PICKUP *pickup = new PICKUP(type, subtype);
		pickup->pos = pos;
		return true;
	}

	return false;
}


void GAMECONTROLLER_WA::on_character_spawn(class CHARACTER *chr)
{
	GAMECONTROLLER::on_character_spawn(chr);
	chr->increase_health(10);
	chr->increase_armor(10);
	for(int i=0; i !=5; i++)
	{	
		chr->weapons[i].got=0;
		chr->weapons[i].ammo=0;
	}
	if(config.sv_weapon_arena != -1)
	{
		chr->weapons[config.sv_weapon_arena].got=1;
		chr->weapons[config.sv_weapon_arena].ammo=50;
		chr->active_weapon=config.sv_weapon_arena;
		chr->last_weapon=config.sv_weapon_arena;
	}
}

